import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Scanner;

public class SystemManagerModule {
    private final Scanner scanner = new Scanner(System.in);
    private final List<String> logs = new ArrayList<>();
    
    public void execute() {
        while (true) {
            System.out.println("\n===== 系统管理 =====");
            System.out.println("1. 系统健康监测");
            System.out.println("2. 查看系统日志");
            System.out.println("3. 添加操作日志");
            System.out.println("4. 返回主菜单");
            System.out.print("请选择操作(1-4): ");
            
            int choice = scanner.nextInt();
            scanner.nextLine();  // 消耗换行符
            
            switch (choice) {
                case 1 -> monitorSystem();
                case 2 -> showLogs();
                case 3 -> addLog();
                case 4 -> { return; }
                default -> System.out.println("无效选择，请重新输入");
            }
        }
    }
    
    private void monitorSystem() {
        System.out.println("系统健康监测: 所有服务运行正常");
        addLog("执行系统健康检查");
    }
    
    private void showLogs() {
        if (logs.isEmpty()) {
            System.out.println("没有系统日志");
            return;
        }
        
        System.out.println("\n=== 系统日志 ===");
        for (int i = 0; i < logs.size(); i++) {
            System.out.println((i+1) + ". " + logs.get(i));
        }
    }
    
    private void addLog() {
        System.out.print("请输入日志内容: ");
        String log = scanner.nextLine();
        logs.add("[" + new Date() + "] " + log);
        System.out.println("日志添加成功");
    }
    
    public void addLog(String log) {
        logs.add("[" + new Date() + "] " + log);
    }
}